<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>处理视频比例 | 简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../part0/handle_video_view_change.html" />
    
    
    <link rel="prev" href="../part0/get_start_play.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.4"
        data-chapter-title="处理视频比例"
        data-filepath="part0/handle_video_ratio.md"
        data-basepath=".."
        data-revision="Thu Apr 14 2016 20:52:34 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="part0/index.html">
            
                
                    <a href="../part0/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        快速开始
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="part0/import_project.html">
            
                
                    <a href="../part0/import_project.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        集成工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="part0/demoyun_xing_xiao_guo_ji_shi_yong.html">
            
                
                    <a href="../part0/demoyun_xing_xiao_guo_ji_shi_yong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        demo运行效果及使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="part0/get_start_play.html">
            
                
                    <a href="../part0/get_start_play.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        启动播放器
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.4" data-path="part0/handle_video_ratio.html">
            
                
                    <a href="../part0/handle_video_ratio.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        处理视频比例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="part0/handle_video_view_change.html">
            
                
                    <a href="../part0/handle_video_view_change.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        处理屏幕旋转
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="part0/pano_quick_start.html">
            
                
                    <a href="../part0/pano_quick_start.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        全景播放
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="part0/hanlde_proguard.html">
            
                
                    <a href="../part0/hanlde_proguard.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        关于混淆
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="part1/index.html">
            
                
                    <a href="../part1/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        第一章
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="part1/player_structure.html">
            
                
                    <a href="../part1/player_structure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        播放器基本架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="part1/player_api_Intro.html">
            
                
                    <a href="../part1/player_api_Intro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        LetvPlayer播放器API说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="part1/playcontext_introduction.html">
            
                
                    <a href="../part1/playcontext_introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        PlayContext ApI说明
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="download/download_module.html">
            
                
                    <a href="../download/download_module.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        下载模块
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="download/download_letter.html">
            
                
                    <a href="../download/download_letter.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        快速接入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="download/download_center.html">
            
                
                    <a href="../download/download_center.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        DownloadCenter API说明文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="download/download_observer.html">
            
                
                    <a href="../download/download_observer.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        LeDownloadObserver API说明文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="download/download_info.html">
            
                
                    <a href="../download/download_info.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        LeDownloadInfo API 说明文档
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="update.html">
            
                
                    <a href="../update.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        更新说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="fqa.html">
            
                
                    <a href="../fqa.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Q&amp;A
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5904;&#x7406;&#x89C6;&#x9891;&#x6BD4;&#x4F8B;">&#x5904;&#x7406;&#x89C6;&#x9891;&#x6BD4;&#x4F8B;</h1>
<p>&#x5982;&#x679C;&#x5E78;&#x8FD0;&#x7684;&#x8BDD;&#xFF0C;&#x4F60;&#x7684;&#x64AD;&#x653E;&#x5668;&#x5DF2;&#x7ECF;&#x53EF;&#x4EE5;&#x6B63;&#x5E38;&#x64AD;&#x653E;&#x4E86;&#xFF0C;&#x4F46;&#x9057;&#x61BE;&#x7684;&#x662F;&#xFF0C;&#x89C6;&#x9891;&#x7684;&#x6BD4;&#x4F8B;&#x663E;&#x793A;&#x662F;&#x4E0D;&#x5BF9;&#x7684;&#xFF0C;&#x6B64;&#x65F6;&#x9700;&#x8981;&#x83B7;&#x53D6;&#x5230;&#x89C6;&#x9891;&#x7684;&#x6BD4;&#x4F8B;&#xFF0C;&#x7136;&#x540E;&#x5BF9;&#x663E;&#x793A;&#x7684;view&#x8BBE;&#x7F6E;&#x4E00;&#x4E0B;&#x6BD4;&#x4F8B;&#x3002;</p>
<h1 id="&#x5904;&#x7406;-mediaeventvideosize-&#x56DE;&#x8C03;&#x4E8B;&#x4EF6;">&#x5904;&#x7406; MEDIA_EVENT_VIDEO_SIZE &#x56DE;&#x8C03;&#x4E8B;&#x4EF6;</h1>
<p>&#x89C6;&#x9891;&#x64AD;&#x653E;&#x7B2C;&#x4E00;&#x5E27;&#x753B;&#x9762;&#x4E4B;&#x524D;&#xFF0C;&#x4F1A;&#x6536;&#x5230;MEDIA_EVENT_VIDEO_SIZE&#x7684;&#x56DE;&#x8C03;&#x4E8B;&#x4EF6;,&#x6B64;&#x65F6;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5230;&#x89C6;&#x9891;&#x7684;&#x5BBD;&#x9AD8;&#x3002;</p>
<pre><code class="lang-java">
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> width;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> height;
    player.setOnPlayStateListener(<span class="hljs-keyword">new</span> OnPlayStateListener() {
            <span class="hljs-annotation">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">videoState</span><span class="hljs-params">(<span class="hljs-keyword">int</span> state, Bundle bundle)</span> </span>{
                <span class="hljs-keyword">if</span> (player == <span class="hljs-keyword">null</span>) {
                    <span class="hljs-keyword">return</span>;
                }
                <span class="hljs-keyword">switch</span> (state) {

                ......

                <span class="hljs-keyword">case</span> ISplayer.MEDIA_EVENT_VIDEO_SIZE:<span class="hljs-comment">//&#x83B7;&#x53D6;&#x5230;&#x89C6;&#x9891;&#x5BBD;&#x9AD8;</span>
                    width=player.getVideoWidth();
                    height=player.getVideoHeight();

                    <span class="hljs-comment">//1.&#x7B97;&#x51FA;&#x89C6;&#x9891;&#x6BD4;&#x4F8B;</span>
                    <span class="hljs-keyword">float</span> ratio=(<span class="hljs-keyword">float</span>)width/height;

                    <span class="hljs-comment">//2.&#x83B7;&#x53D6;&#x5230;&#x5F53;&#x524D;&#x663E;&#x793A;view&#x7684;&#x5BBD;&#x9AD8;</span>
                    <span class="hljs-comment">//3.&#x91CD;&#x65B0;&#x8BA1;&#x7B97;&#x5BBD;&#x9AD8;</span>
                    <span class="hljs-comment">//4.&#x91CD;&#x65B0;&#x8BBE;&#x7F6E;layoutParams</span>
                    mView.setLayoutParams();

                    <span class="hljs-keyword">break</span>;
                ......
                }
            }
        });
</code></pre>
<h1 id="&#x5904;&#x7406;surfaceview-&#x7684;surfacechanged&#x65B9;&#x6CD5;">&#x5904;&#x7406;SurfaceView &#x7684;surfaceChanged()&#x65B9;&#x6CD5;</h1>
<p>&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E86;<code>SurfaceView</code> &#x663E;&#x793A;&#x89C6;&#x9891;&#x5185;&#x5BB9;&#x65F6;&#x5019;&#xFF0C;&#x5F53;surfaceview&#x7684;&#x5BBD;&#x9AD8;&#x53D8;&#x5316;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x89E6;&#x53D1;&#x7684;surfaceChanged()&#x65B9;&#x6CD5;&#xFF0C;&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;&#x89C6;&#x9891;&#x7684;&#x6BD4;&#x4F8B;&#xFF0C;&#x5E94;&#x8BE5;&#x544A;&#x8BC9;&#x64AD;&#x653E;&#x5668;&#x6B64;&#x65F6;&#x663E;&#x793A;&#x7684;view&#x5DF2;&#x7ECF;&#x6539;&#x53D8;&#x4E86;&#x5927;&#x5C0F;&#x3002;</p>
<pre><code class="lang-java">    surfaceView.getHolder().addCallback(<span class="hljs-keyword">new</span> Callback() {

            <span class="hljs-annotation">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">surfaceDestroyed</span><span class="hljs-params">(SurfaceHolder holder)</span> </span>{
                ......
            }

            <span class="hljs-annotation">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">surfaceCreated</span><span class="hljs-params">(SurfaceHolder holder)</span> </span>{
                ......
            }

            <span class="hljs-annotation">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">surfaceChanged</span><span class="hljs-params">(SurfaceHolder holder, <span class="hljs-keyword">int</span> format, <span class="hljs-keyword">int</span> width, <span class="hljs-keyword">int</span> height)</span> </span>{
                ......
                <span class="hljs-keyword">if</span>(player!=<span class="hljs-keyword">null</span>){
                     PlayerHelper.setViewSizeChange(player, width, height);
                }
            }
        });
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../part0/get_start_play.html" class="navigation navigation-prev " aria-label="Previous page: 启动播放器"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../part0/handle_video_view_change.html" class="navigation navigation-next " aria-label="Next page: 处理屏幕旋转"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
